/*******************************************************************************
 * Copyright (c) 2009 Brian Edginton and Aaron Getz.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Brian Edginton - initial API and implementation
 *     Aaron Getz
 *******************************************************************************/
package org.eclipse.mylyn.internal.eplanner.core;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Map;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.*;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.mylyn.commons.net.AbstractWebLocation;
import org.eclipse.mylyn.commons.net.AuthenticationCredentials;
import org.eclipse.mylyn.commons.net.AuthenticationType;
import org.eclipse.mylyn.commons.net.Policy;
import org.eclipse.mylyn.commons.net.WebUtil;

/**
 * @author edge
 *
 */
public class EPlannerClient {
	

	private static final String USER_AGENT = "EPlannerConnector";
	private static final String QUERY_DELIMITER = "?";
	
	protected String user;
	protected String password;
	protected String characterEncoding;
	protected URL repositoryUrl;
	
	protected boolean authenticated;
	
	private final Map<String, String> configParameters;
	private final AbstractWebLocation location;
	
	private final HttpClient httpClient = new HttpClient(WebUtil.getConnectionManager());
	
	public EPlannerClient(AbstractWebLocation location,
			String characterEncoding, Map<String, String> properties) throws MalformedURLException {
		AuthenticationCredentials credentials = location.getCredentials(AuthenticationType.REPOSITORY);
		if (credentials != null) {
			this.user = credentials.getUserName();
			this.password = credentials.getPassword();
		}
		
		this.repositoryUrl = new URL(location.getUrl());
		this.location = location;
		this.configParameters = properties;
		this.characterEncoding = characterEncoding;
		
		WebUtil.configureHttpClient(httpClient, USER_AGENT);
	}
	
	

}
